package com.example.springboot.controller;

import com.example.springboot.entity.ForumPostFavorite;
import com.example.springboot.service.ForumPostFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/favorites")
public class ForumPostFavoriteController {

    @Autowired
    private ForumPostFavoriteService forumPostFavoriteService;

    @PostMapping
    public void favoritePost(@RequestBody ForumPostFavorite favorite) {
        forumPostFavoriteService.favoritePost(favorite);
    }

    @DeleteMapping("/{postId}/{userId}")
    public void unfavoritePost(@PathVariable Integer postId, @PathVariable Integer userId) {
        forumPostFavoriteService.unfavoritePost(postId, userId);
    }

    @GetMapping("/{postId}/{userId}")
    public boolean isPostFavoritedByUser(@PathVariable Integer postId, @PathVariable Integer userId) {
        return forumPostFavoriteService.isPostFavoritedByUser(postId, userId);
    }
    @GetMapping("/user/{userId}")
    public List<ForumPostFavorite> getFavoritesByUserId(@PathVariable Integer userId) {
        return forumPostFavoriteService.getFavoritesByUserId(userId);
    }
}